#include"Processbar.h"
#include<string.h>
#include<unistd.h>
//void ForTest()
//{
//  printf("this is for test\n");
//  printf("this is for test\n");
//  printf("this is for test\n");
//  printf("this is for test\n");
//  printf("this is for test\n");
//  printf("this is for test\n");
//  printf("this is for test\n");
//}

#define Length 101
#define Style '='
const char *lable = "|/-\\" ;
//version 1
//void ProcBar()
//{
//     char bar[Length];
//     memset(bar,'\0',sizeof(bar));
//     int len = strlen(lable); 
//     int cnt = 0;
//     while(cnt <= 100)
//     {
//       printf("[%-100s][%2d%%][%c]\r",bar,cnt,lable[cnt%len]);
//      fflush(stdout); 
//       bar[cnt++] = Style;
//       usleep(50000);
//     }
//     printf("\n");
//}
//version2

void Printf_color(const char* s)
{
  printf("\033[0m\033[1;31m%s\033[0m",s);

}
void ProcBar(double total,double current)
{

     char bar[Length];
     memset(bar,'\0',sizeof(bar));
     int len = strlen(lable); 
     int cnt = 0;
     double rate = (current * 100.0)/total;
     int loop_count = (int)rate;
     while(cnt <= loop_count)
     {
       //printf("[%-100s][%.1lf%%][%c]\r",bar,rate,lable[cnt%len]);
       //fflush(stdout); 
       bar[cnt++] = Style;
     }
     
       printf("\033[1;37;44m[%-100s]\033[0m \033[1;37;44m[%.1lf%%][%c]\033[0m\r",bar,rate,lable[cnt%len]);
       fflush(stdout); 
}

